﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProgNetComponents.Ini;

namespace ProgNetDxComponents.ExtenderProviders.Options
{
    public class IniOptionGrabber : OptionGrabber
    {
        private IniFile IniFile = null;
        private string _Category = "OPTIONS";

        public IniOptionGrabber(string file)
        {
            IniFile = new IniFile(file);
        }

        protected override bool _SetOptionValueDirect(string name, object value)
        {
            return IniFile.WriteValueToFile(_Category, name, value.AsString());
        }

        protected override bool _SetOptionValue(string name, object value)
        {
            IniFile.WriteValueToCache(_Category, name, value.AsString());
            return true;
        }

        public override bool HasOption(string name)
        {
            return IniFile.HasValue(_Category, name);
        }

        protected override void _GetAllOptions()
        {
            IniFile.ReadIni();
        }

        public override object GetOptionValue(string name)
        {
            return IniFile.GetValueFormCache(_Category, name);
        }

        protected override bool SaveOptions()
        {
            return IniFile.SaveIni();
        }
    }
}
